package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

// PublishScheduleLog 投放计划记录表
type PublishScheduleLog struct {
	ID         string `json:"id" gorm:"column:id;primaryKey;type:int;size:64;comment:主键"`
	MerchantID string `json:"merchant_id" gorm:"column:merchant_id;primaryKey;type:varchar(30);not null;default:'';index:merchant_id;comment:商户id"`
	ScheduleID string `json:"schedule_id" gorm:"column:schedule_id;type:int;size:64;comment:计划ID"`
	RobotName  string `json:"robot_name" gorm:"column:robot_name;type:varchar(20);comment:设备名称"`
	Count      int64  `json:"count" gorm:"column:count;type:int;size:64;not null;default:0;comment:播放次数"`
	CreatedAt  int64  `json:"created_at" gorm:"column:created_at;autoCreateTime;type:int;size:64;not null;default:0;index:created_at;comment:创建时间"`
	UpdatedAt  int64  `json:"updated_at" gorm:"column:updated_at;autoUpdateTime;type:int;size:64;not null;default:0;index:updated_at;comment:更新时间"`
}

// TableName 表名
func (PublishScheduleLog) TableName() string {
	return "publish_schedule_log"
}

// BeforeCreate 自增id
func (l *PublishScheduleLog) BeforeCreate(tx *gorm.DB) (err error) {
	if l.ID == "" {
		// id为空时，自动添加id
		uuid, err := helper.UUID{}.String()
		if err != nil {
			return err
		}
		l.ID = uuid
	}
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &PublishScheduleLog{})
}
